<?php

class yzRegistry extends yzCore {

	protected $aVars = array();
	
	public function setVar($sNameSpace, $sName, $mValue){
		
		return $this->aVars[$sNameSpace][$sName] = $mValue;
 
	} // function
	
	public function addVar($sNameSpace, $mValue){
        
        return $this->aVars[$sNameSpace][] = $mValue;
 
    } // function

	public function getVar($sNameSpace, $sName){
		
		if (isset( $this->aVars[$sNameSpace][$sName])){
			
			return  $this->aVars[$sNameSpace][$sName];
			
		} else {
			
			 return null; 
		
		} // if
		
	} // function
	
	public function isSetVar($sNameSpace, $sName){
		
		return isset($this->aVars[$sNameSpace][$sName]);

	} // function
	
	public function unsetVar($sNameSpace, $sName){
		
		if (isset( $this->aVars[$sNameSpace][$sName])){
			
			unset($this->aVars[$sNameSpace][$sName]);
			
			return  true;
			
		} else {
			
			 return false; 
		
		} // if		
	
	} // function
	
	public function importVars($sNameSpace, $aVars){
		
		foreach ($aVars as $mKey=>$mValue){
			
			$this->aVars[$sNameSpace][strval($mKey)] = $mValue;
			
		} // foreach
		
		return count($aVars);
		
	} // function
	
	public function setNameSpace($sNameSpace, $aVars){
		
		$this->aVars[$sNameSpace] = $aVars;
		
		return count($aVars);
		 
	} // function
	
	public function getNameSpace($sNameSpace){
		
		if (isset( $this->aVars[$sNameSpace])){
			
			return  (array)$this->aVars[$sNameSpace];
			
		} else {
			
			 return array(); 
		
		} // if
		
	} // function
	
	public function unsetNameSpace($sNameSpace){
		
		if (isset( $this->aVars[$sNameSpace])){
			
			unset($this->aVars[$sNameSpace]);
			
			return  true;
			
		} else {
			
			 return false; 
		
		} // if		
	
	} // function
	
	public function isSetNameSpace($sNameSpace){
		
		return isset($this->aVars[$sNameSpace]);
		
	} // function
	
	public function getVars($sNameSpace = null, $sPattern = null, $bRawPCRE = false){

		if ($sNameSpace === null){
			
			return $this->aVars;
		
		} else if (!$this->isSetNameSpace($sNameSpace)){
			
			return array();
			
		} else if ($sPattern == null){
			
			return $this->aVars[$sNameSpace];
			
		} else {		
			
			if ($bRawPCRE !== true){
				
				$sPattern = '/^'.str_replace(array('\\','.','*','?'),array('\\\\','\.','.*','.{1}'),$sPattern).'$/iU'; 
				
			} // if
		  
			return array_intersect_key($this->aVars[$sNameSpace], array_fill_keys(preg_grep($sPattern, array_keys($this->aVars[$sNameSpace])),null));
		
		} // if	
		
	} // function getVars()
		
} // class

?>